package com.tj.jinzao.presenter;

import android.util.Log;

import com.tj.jinzao.api.SubscriberCallBack;
import com.tj.jinzao.base.BasePresenter;
import com.tj.jinzao.callback.IListFriendView;
import com.tj.jinzao.model.FriendBean;
import com.tj.jinzao.model.ResultResponse;
import com.tj.jinzao.model.User;

import java.util.HashMap;
import java.util.List;

/**
 * Created by LiuYX on 2019/4/19.
 */

public class FriendPresenter extends BasePresenter<IListFriendView<List<FriendBean>>> {
    public FriendPresenter(IListFriendView<List<FriendBean>> view) {
        super(view);
    }
    //添加好友
    public void getAddFriend(HashMap<String, Object> map) {
        Log.w("添加好友",map.toString());
        addSubscription(mApiService.getAddFriend(map), new SubscriberCallBack<FriendBean>(mView.getContext()) {
            @Override
            protected void onSuccess(FriendBean list) {
                if (mView != null) mView.onAddFriendSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onFailed(response);
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }

            @Override
            protected void onPageSuccess(int currentPage, int allPage, int allSize) {
                if (mView != null) mView.onAddFriendSuccess(null);
            }
        });
    }
    //好友列表
    public void getFriendList(HashMap<String, Object> map) {
        addSubscription(mApiService.getFriendList(map), new SubscriberCallBack<List<FriendBean>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<FriendBean> list) {
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }

            @Override
            protected void onPageSuccess(int currentPage, int allPage, int allSize) {
                if (mView != null) mView.onRequestSuccessPage(currentPage, allPage, allSize);
            }
        });
    }
    //获取指定咨询师下的用户列表
    public void getFriend(HashMap<String, Object> map) {
        addSubscription(mApiService.getFriendListMM(map), new SubscriberCallBack<List<FriendBean>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<FriendBean> list) {
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }

            @Override
            protected void onPageSuccess(int currentPage, int allPage, int allSize) {
                if (mView != null) mView.onRequestSuccessPage(currentPage, allPage, allSize);
            }
        });
    }
    //咨询师列表
    public void getTalk(HashMap<String, Object> map) {
        addSubscription(mApiService.getTalk(map), new SubscriberCallBack<List<FriendBean>>(mView.getContext()) {
            @Override
            protected void onSuccess(List<FriendBean> list) {
                if (mView != null) mView.onRequestSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onRequestError(response.getMessage());
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }

            @Override
            protected void onPageSuccess(int currentPage, int allPage, int allSize) {
                if (mView != null) mView.onRequestSuccessPage(currentPage, allPage, allSize);
            }
        });
    }
    //个人资料
    public void getPersonData(long id) {
        addSubscription(mApiService.getUserInfo(id), new SubscriberCallBack<User>(mView.getContext()) {
            @Override
            protected void onSuccess(User list) {
                if (mView != null) mView.onUserInfoSuccess(list);
            }

            @Override
            protected void onFailure(ResultResponse response) {
                if (mView != null) mView.onUserInfoFailed(response);
            }

            @Override
            protected boolean isShowProgress() {
                return false;
            }

            @Override
            protected void onPageSuccess(int currentPage, int allPage, int allSize) {
                if (mView != null) mView.onUserInfoFailed(null);
            }
        });
    }

}
